package com.ruoyi.api.controller.user;

import com.ruoyi.api.controller.common.AbstractApiController;
import com.ruoyi.business.domain.dto.api.user.AddMyBabyDTO;
import com.ruoyi.business.domain.dto.api.user.EditMyBabyDTO;
import com.ruoyi.business.domain.koc.TbUserBaby;
import com.ruoyi.business.service.koc.ITbUserBabyService;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.Arrays;

/**
 * 我的宝宝
 */
@Validated
@Api(value = "我的宝宝管理控制器", tags = {"小程序用户我的宝宝管理管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/miniapp/user/baby")
public class ApiUserBabyController extends AbstractApiController {

    @Resource
    private ITbUserBabyService userBabyService;

    /**
     * 查询用户宝宝列表
     */
    @ApiOperation("查询我的宝宝信息")
    @GetMapping("/page-list")
    public TableDataInfo<TbUserBaby> queryMyBabyPage(PageQuery pageQuery) {
        return userBabyService.queryMyBabyPageList(getUserId(), pageQuery);
    }

    /**
     * 添加我的宝宝信息
     */
    @ApiOperation("添加我的宝宝信息")
    @PostMapping("/add")
    public R<Boolean> add(@Validated @RequestBody AddMyBabyDTO dto) {
        return R.ok(userBabyService.addMyBaby(getUserId(), dto));
    }


    /**
     * 修改我的宝宝信息
     */
    @ApiOperation("修改我的宝宝信息")
    @PostMapping("/edit")
    public R<Boolean> edit(@Validated @RequestBody EditMyBabyDTO dto) {
        return R.ok(userBabyService.editMyBaby(getUserId(), dto));
    }


    /**
     * 删除我的宝宝
     */
    @ApiOperation("删除我的宝宝")
    @DeleteMapping("/del/{ids}")
    public R<Boolean> remove(@ApiParam("主键串")
                             @NotEmpty(message = "主键不能为空")
                             @PathVariable String[] ids) {
        return R.ok(userBabyService.deleteByIds(Arrays.asList(ids)));
    }


}
